#include <compat/endian.h>

unsigned short os_read16_le(const unsigned char *buf)
{
	return (unsigned short)(((unsigned short)buf[0]) |
		((unsigned short)buf[1] << 8));
}

unsigned int os_read32_le(const unsigned char *buf)
{
	return ((unsigned int)buf[0]) | ((unsigned int)buf[1] << 8) |
		((unsigned int)buf[2] << 16) | ((unsigned int)buf[3] << 24);
}

void os_write32_le(const int value, unsigned char *buffer)
{
	buffer[0] = (char)(value & 0x000000FF);
	buffer[1] = (char)((value & 0x0000FF00) >> 8);
	buffer[2] = (char)((value & 0x00FF0000) >> 16);
	buffer[3] = (char)((value & 0xFF000000) >> 24);
}

void os_write64_le(const os_int64 value, unsigned char *buffer)
{
	os_write32_le((int)value, buffer);
	os_write32_le((int)(value >> 32), buffer + 4);
}